package demo3;

import demo2.Person;

import java.util.Arrays;
import java.util.Comparator;

interface IA{
    void test();
}
public class Test {

    public static int data = 10;
    public void func(){
        data++;
        System.out.println(data);
    }

    public static void main8(String[] args) {
        Test test = new Test();
        test.func();
    }

    public static void main(String[] args) {
        new IA(){
            public static int a = 10;
            // a = 1000;

            @Override
            public void test() {
                int c = 10;
                c = 20;
                System.out.println(c);
                System.out.println("a = " + a);
            }
        }.test();
    }

    public static void main6(String[] args) {
        int a = 10;
        // 表示一个类 实现IA接口
        new IA(){
            @Override
            public void test() {
                System.out.println("a = " + a);
            }
        }.test();
    }

    public static void main5(String[] args) {
        Comparator comparator = new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.age - o2.age;
            }
        };

        Student[] students = new Student[3];
        students[0] = new Student("zhangsan", 10);
        students[1] = new Student("lisi", 5);
        students[2] = new Student("abc", 15);

        // Arrays.sort(students, comparator);
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o1.age - o2.age;
            }
        });

        System.out.println(Arrays.toString(students));
    }

    public static void main4(String[] args) {
        // 有一个类 实现了IA这个接口
        IA ia = new IA(){
            @Override
            public void test() {
                System.out.println("重写了接口的方法");
            }
        };

        ia.test();
    }

    public void test(){
        System.out.println("demo4.Test::()执行了");
    }

    public static void main3(String[] args) {
        // 相当于继承了Test类
        Test t = new Test(){
            @Override
            public void test() {
                System.out.println("重写的test方法被执行了...");
            }
        };

        t.test();
    }
    public static void main2(String[] args) {
        OuterClass2.InnerClass innerClass = new OuterClass2.InnerClass();
        innerClass.testInner();

        OuterClass2 outerClass2 = new OuterClass2();
        outerClass2.test2();

    }

    public static void main1(String[] args) {
        OuterClass1 outerClass1 = new OuterClass1();
        OuterClass1.InnerClass innerClass =  outerClass1.new InnerClass();
        OuterClass1.InnerClass innerClass4 = outerClass1.new InnerClass();

        innerClass.testInner();

        OuterClass1.InnerClass innerClass1 = new OuterClass1().new InnerClass();
        OuterClass1.InnerClass innerClass2 = new OuterClass1().new InnerClass();
        OuterClass1.InnerClass innerClass3 = new OuterClass1().new InnerClass();

        new OuterClass1().test();
        new OuterClass1().test();
        new OuterClass1().test();
        new OuterClass1().test();

        outerClass1.test();
        outerClass1.test();
        outerClass1.test();
        outerClass1.test();
    }
}
